package com.jade.framework.web.controller;

import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * 映射 xxx.v 到 /WEB-INF/jsp/xxx.jsp。/WEB-INF/jsp的路径通过viewResoler来进行配置。
 *
 * @author lyyang
 * @version 1.0 13-5-1 下午4:51
 */
@Controller
@Api(value = "映射", hidden = true)
public class JspForwardController
{
    @RequestMapping (value = "/**/*.v", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(value = "--", hidden = true)
    public ModelAndView forward(HttpServletRequest request)
    {
        String url = request.getServletPath();
        url = url.substring(0, url.lastIndexOf(".v"));
        ModelAndView result = new ModelAndView(url);
        //将url中的参数写到ModelAndView中去,以方便给响应页面使用
        Enumeration it = request.getParameterNames();
        while (it.hasMoreElements()) {
            String key = (String)it.nextElement();
            result.addObject(key, request.getParameter(key));
        }
        return result;
    }
}
